from fastapi import HTTPException, Request
from fastapi.responses import JSONResponse

from app.core.BaseResponse import UnicornException


async def http_error_handler(_: Request, exc: HTTPException):
    return JSONResponse({
        "code": exc.status_code,
        "message": exc.detail,
        "data": exc.detail
    }, status_code=exc.status_code)


async def unicorn_exception_handler(_: Request, exc: UnicornException):
    return JSONResponse({
        "code": exc.code,
        "message": exc.errmsg,
        "data": exc.data,
    })
